<script setup lang="ts">
import {useRouter} from "vue-router";
import lodash from 'lodash-es'

/**
 * @see {@link https://vuejs.org/api/sfc-script-setup.html#defineoptions}
 */
defineOptions({
  name: "Audit",
  inheritAttrs: false,
});
import {
  getAuditPage,
  exportAudit,
  importAudit,
  reBill
} from "@/api/audit";
import {
  getDoneAuditPage,
} from "@/api/doneAudit";
import {
  listAll,
} from "@/api/store";

import { AuditQuery } from "@/api/audit/types";
import {getAllRole} from "@/api/role";
import {CompanyForm} from "@/api/company/types";
import {StoreForm} from "@/api/store/types";
import {getCompanyList} from "@/api/company";
import {RoleForm} from "@/api/role/types";
import { ElLoading, UploadFile } from "element-plus";
const router = useRouter();

const queryFormRef = ref(ElForm); // 查询表单

const loading = ref(false);
const ids = ref([]);
const total = ref(0);
const doneTotal = ref(0);
const showMore = ref(false);
const activeTab = ref('audit');
const excelFile = ref<File>();
const excelFilelist = ref<File[]>([]);
const importMsg = ref([])
const tableHeight = ref(540)
const importDialog = reactive<DialogOption>({
  title: "核销单导入",
  visible: false,
});
const resultDialog = reactive<DialogOption>({
  title: "导入错误信息",
  visible: false,
});

const queryParams = reactive<AuditQuery>({
  pageNum: 1,
  pageSize: 20,
	mainTypeName: 'error'
});
const auditList = ref<[]>();
const doneAuditList = ref<[]>();
const storeList = ref<[]>([])
const roleList = ref<RoleForm[]>();
const companyList = ref<CompanyForm[]>();
const dateList = ref<[]>([])


/**
 * 查询
 */
function handleAuditQuery() {
  loading.value = true;
	queryParams.startDate = null;
	queryParams.endDate = null;
  if (lodash.size(dateList.value) > 0) {
	  queryParams.startDate = dateList.value[0];
	  queryParams.endDate = dateList.value[1];
	}
  getAuditPage(queryParams)
    .then(({ data }) => {
	  	auditList.value = data.list;
      total.value = data.total;
	  	getHeight()
    })
    .finally(() => {
      loading.value = false;
    });
}

/** 重置查询 */
function resetQuery() {
  queryParams.pageNum = 1;
  handleAuditQuery();
}

/**
 * 跳转到详情页
 * @param id
 * @param goType 跳转类型（0：待审核，1：已办未归档、归档）
 */
function goDetail(id: number, linkNo: string, goType: number) {
  router.push({
    name: 'AuditDetail',
    state: {
      id: id,
			linkNo: linkNo,
      goType: goType
    }
  })
}

function getDoneAuditPageHandle() {
  loading.value = true;
  getDoneAuditPage(queryParams)
          .then(({ data }) => {
            doneAuditList.value = data.list;
            doneTotal.value = data.total;
			  		getHeight()
          })
          .finally(() => {
            loading.value = false;
          });
}

/**
 * 切换tab事件
 * @param e
 */
function tabClick(e?: any) {
  search(e.props.name)
}

/**
 * 查询方法
 * @param tabName
 */
function search(tabName: string) {
  queryParams.ownerLoss = queryParams.ownerLossValue ? 1 : null;
  if (tabName === 'audit') {
    handleAuditQuery()
  }else if(tabName === 'done') {
    queryParams.status = 0
    getDoneAuditPageHandle()
  }else if(tabName === 'file') {
    queryParams.status = 1
    getDoneAuditPageHandle()
  }
}

/**
 * 获取所有店铺
 */
function getAllStore() {
	listAll().then((response) => {
		storeList.value = []
		const group_store = lodash.groupBy(response.data, 'storeKeyName');
		for (let key in group_store) {
			storeList.value.push({'label': key, 'options': group_store[key]})
		}
	})
}

/**
 * 获取角色下拉列表
 */
function getRoleOptions() {
  getAllRole().then((response) => {
    roleList.value = response.data;
  });
}

/**
 * 获取入账主体列表
 *
 */
function getAllCompanyList() {
  getCompanyList().then((response) => {
    companyList.value = response.data;
  });
}

/** 行选中事件 */
function handleSelectionChange(selection: any) {
  ids.value = selection.map((item: any) => item.id);
}

/** 导出待审核核销单 */
function handleAuditExport() {
	const importLoading = ElLoading.service({
		lock: true,
		text: '导出中...',
		background: 'rgba(0, 0, 0, 0.7)',
	})
  exportAudit(ids.value, queryParams).then((response: any) => {
    const blob = new Blob([response.data], {
      type: "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet;charset=utf-8",
    });
    const a = document.createElement("a");
    const href = window.URL.createObjectURL(blob); // 下载的链接
    a.href = href;
    a.download = decodeURI(
            response.headers["content-disposition"].split(";")[1].split("=")[1]
    ); // 获取后台设置的文件名称
    document.body.appendChild(a);
    a.click(); // 点击导出
    document.body.removeChild(a); // 下载完成移除元素
    window.URL.revokeObjectURL(href); // 释放掉blob对象
  }).finally(() => importLoading.close());
}

/** 打开导入弹窗 */
async function openImportDialog() {
  importDialog.visible = true;
}

/**
 * Excel文件change事件
 *
 * @param file
 */
function handleExcelChange(file: UploadFile) {
	if (file.size !== undefined) {
		if (file.size > 20*1024*1024) {
			ElMessage.warning("上传文件大小已经超过20M，请尝试拆分成多个文件再上传");
			return false
		}
	}
  if (!/\.(csv|xlsx|xls|XLSX|XLS|CSV)$/.test(file.name)) {
    ElMessage.warning("上传Excel只能为xlsx、xls、csv格式");
    excelFile.value = undefined;
    excelFilelist.value = [];
    return false;
  }
  excelFile.value = file.raw;
}

/** 导入用户提交 */
function handleAuditImport() {
    if (!excelFile.value) {
      ElMessage.warning("上传Excel文件不能为空");
      return false;
    }
    importAudit(excelFile.value).then((response) => {
      closeImportDialog();
      if (response.data.length > 0) {
        importMsg.value = response.data
        resultDialog.visible = true
      }else{
        ElMessage.success('导入成功');
      }
      search(activeTab.value);
    });
}

/**  关闭导入弹窗 */
function closeImportDialog() {
  importDialog.visible = false;
  excelFile.value = undefined;
  excelFilelist.value = [];
}

/**  关闭导入弹窗 */
function closeImportResultDialog() {
  resultDialog.visible = false;
}

/**
 * 反审核
 */
function reBillHandle(){
  if (ids.value.length === 0) {
    ElMessage.warning('请勾选需要重跑的数据');
  }
  reBill(ids.value).then((response) => {
    ElMessage.success('操作成功');
    handleAuditQuery()
  });
}

function getHeight() {
	if (showMore.value) {
		if (activeTab.value === 'audit') {
			if (auditList.value && auditList.value.length > 0) {
				tableHeight.value = 424
			} else {
				tableHeight.value = 130
			}
		}else{
			if (doneAuditList.value && doneAuditList.value.length > 0) {
				tableHeight.value = 467
			} else {
				tableHeight.value = 130
			}
		}
	}else{
		if (activeTab.value === 'audit') {
			if (auditList.value && auditList.value.length > 0) {
				tableHeight.value = 530
			}else{
				tableHeight.value = 130
			}
		}else{
			if (doneAuditList.value && doneAuditList.value.length > 0) {
				tableHeight.value = 583
			} else {
				tableHeight.value = 130
			}
		}
	}
}

function showMoreHandle() {
	showMore.value = !showMore.value
	getHeight()
}

onMounted(() => {
  handleAuditQuery(); // 初始化标准账单配置列表数据
  getAllStore()
  getRoleOptions()
  getAllCompanyList()
});
</script>

<template>
  <div class="app-container">
    <el-row :gutter="20">

      <el-col>
        <div class="search-container">
          <el-form ref="queryFormRef" :model="queryParams" :inline="true">
						<el-form-item label="业务日期">
							<el-date-picker
									v-model="dateList"
									type="daterange"
									value-format="YYYY-MM-DD"
									:editable="false"
									clearable
									style="width:220px"
									start-placeholder="开始日期"
									end-placeholder="结束日期"
							/>
						</el-form-item>
						<el-form-item label="电商平台店铺名称" prop="thirdSourceCode">
							<el-select class="yz-el-select" v-model="queryParams.thirdSourceCode" filterable clearable placeholder="请选择店铺">
								<el-option-group
									v-for="group in storeList"
									:key="group.label"
									:label="group.label"
								>
									<el-option
										v-for="item in group.options"
										:key="item.id"
										:label="item.innerSystemStoreName"
										:value="item.commercePlatformStoreCode"
									/>
								</el-option-group>
							</el-select>
						</el-form-item>
						<el-form-item label="原始账单ID" prop="linkNo">
							<el-input
									v-model="queryParams.linkNo"
									placeholder="原始账单ID"
									clearable
									style="width: 200px"
							/>
						</el-form-item>
						<el-form-item label="核销结果分类" prop="mainTypeName">
							<dictionary v-model="queryParams.mainTypeName" type-code="jgfl"/>
						</el-form-item>
            <el-form-item v-if="showMore" label="入账主体" prop="receiveCompany">
              <el-select
                      v-model="queryParams.receiveCompany"
                      placeholder="全部"
                      clearable
											class="yz-el-select"
              >
                <el-option
                        v-for="item in companyList"
                        :key="item.code"
                        :label="item.name"
                        :value="item.code"
                />
              </el-select>
            </el-form-item>
						<el-form-item v-if="showMore" label="内部系统店铺名称" prop="shopCode">
							<el-select
									v-model="queryParams.shopCode"
									placeholder="全部"
									clearable
									class="yz-el-select"
							>
								<el-option
										v-for="item in storeList"
										:key="item.innerSystemStoreCode"
										:label="item.innerSystemStoreName"
										:value="item.innerSystemStoreCode"
								/>
							</el-select>
						</el-form-item>
            <el-form-item v-if="showMore" label="财务系统店铺名称" prop="billSysStore">
              <el-select
                      v-model="queryParams.billSysStore"
                      placeholder="全部"
                      clearable
											class="yz-el-select"
              >
                <el-option
                        v-for="item in storeList"
                        :key="item.financeSystemStoreCode"
                        :label="item.financeSystemStoreName"
                        :value="item.financeSystemStoreCode"
                />
              </el-select>
            </el-form-item>
						<el-form-item v-if="showMore" label="单据编号" prop="keywords">
							<el-input
								v-model="queryParams.keywords"
								placeholder="单据编号"
								clearable
								style="width: 200px"
							/>
						</el-form-item>
            <el-form-item v-if="showMore" label="损失原因" prop="lossReason">
              <dictionary v-model="queryParams.lossReason" type-code="loss"/>
            </el-form-item>
            <el-form-item v-if="showMore" label="责任方" prop="push">
              <el-select
                      v-model="queryParams.push"
                      placeholder="全部"
                      clearable
											class="yz-el-select"
              >
                <el-option
                        v-for="item in roleList"
                        :key="item.code"
                        :label="item.name"
                        :value="item.code"
                />
              </el-select>
            </el-form-item>
            <el-form-item v-if="showMore" label="PO单号" prop="poNo">
              <el-input
                      v-model="queryParams.poNo"
                      placeholder="PO单号"
                      clearable
                      style="width: 200px"
              />
            </el-form-item>
            <el-form-item v-if="showMore" label="自有平台主订单号" prop="onwerPreformNo">
              <el-input
                      v-model="queryParams.onwerPreformNo"
                      placeholder="自有平台主订单号"
                      clearable
                      style="width: 200px"
              />
            </el-form-item>
            <el-form-item v-if="showMore" label="是否自认损失" prop="ownerLossValue">
              <el-checkbox style="margin-top: -3px;" v-model="queryParams.ownerLossValue" label="是" size="large"/>
            </el-form-item>
            <el-form-item>
              <el-button type="primary" @click="search(activeTab)"
              ><i-ep-search />搜索</el-button
              >
              <el-button @click="resetQuery()"><i-ep-refresh />重置</el-button>
							<el-button type="primary" @click="showMoreHandle" >{{showMore ? '隐藏更多' : '更多查询'}}</el-button>
            </el-form-item>
          </el-form>
        </div>

        <el-card shadow="never" >
          <el-tabs type="border-card" v-model="activeTab" @tab-click="tabClick">
            <el-tab-pane label="个人待办" name="audit">
              <div style="margin-bottom: 10px" class="flex justify-between">
                <div>
                  <el-button
                    @click="handleAuditExport"
										v-hasPerm="['sys:audit:export']"
                  ><i-ep-download />导出</el-button
                  >
                  <el-button
                    @click="openImportDialog"
										v-hasPerm="['sys:audit:import']"
                  ><i-ep-top />导入</el-button
                  >
                  <el-button @click="reBillHandle" :disabled="ids.length === 0">重算</el-button>
                </div>
              </div>
              <el-table
                      :height="tableHeight"
                      size="small"
                      :header-row-style="{color: 'dimgray'}"
                      v-loading="loading"
                      :data="auditList"
                      border
                      fixed="left"
                      @selection-change="handleSelectionChange"
              >
                <el-table-column type="selection" width="50" align="center" />
                <el-table-column
                        fixed="left"
                        label="原始单据ID"
                        align="center" show-overflow-tooltip
                        width="180"
                >
                  <template #default="scope">
                    <img v-if="scope.row.manager === 1" src="@/assets/hot.gif"/><a style="color:cornflowerblue"
																																									 href="javascript:;"
																																									 @click="goDetail(scope.row.id, scope.row.linkNo, 0)">{{scope.row.linkNo}}</a>
                  </template>
                </el-table-column>
								<el-table-column
										label="内部系统店铺名称"
										align="center" show-overflow-tooltip
										prop="shopName"
										width="80"
								/>
								<el-table-column
										label="财务系统店铺名称"
										align="center" show-overflow-tooltip
										prop="billSysStoreName"
										width="80"
								></el-table-column>
								<el-table-column
										label="电商平台店铺名称"
										align="center" show-overflow-tooltip
										prop="thirdSourceName"
										width="80"
								></el-table-column>
                <el-table-column
                        label="业务日期"
                        align="center" show-overflow-tooltip
                        prop="businessDate"
                        width="140"
                />
								<el-table-column
										label="核销结果分类"
										align="center" show-overflow-tooltip
										prop="mainTypeName"
										width="80"
								></el-table-column>
								<el-table-column
										label="订单核销细类名称"
										align="center" show-overflow-tooltip
										prop="auditDetailName"
										width="80"
								></el-table-column>
								<el-table-column
									label="核销状态"
									align="center" show-overflow-tooltip
									prop="auditStatus"
									width="80"
								/>
								<el-table-column
										label="应收账款余额"
										align="center" show-overflow-tooltip
										prop="receiveBillAmount"
										width="80"
								></el-table-column>
								<el-table-column
										label="发货金额"
										align="center" show-overflow-tooltip
										prop="sendAmount"
										width="80"
								/>
								<el-table-column
										label="退货金额"
										align="center" show-overflow-tooltip
										width="80"
								>
									<template #default="scope">{{scope.row.returnAmount === 0 ? '' : scope.row.returnAmount}}</template>
								</el-table-column>
								<el-table-column
										label="收款金额"
										align="center" show-overflow-tooltip
										prop="receiveAmount"
										width="80"
								/>
								<el-table-column
										label="退款金额"
										align="center" show-overflow-tooltip
										width="80"
								>
									<template #default="scope">{{scope.row.refundAmount === 0 ? '' : scope.row.refundAmount}}</template>
								</el-table-column>
								<el-table-column
										label="保证金退款金额"
										align="center" show-overflow-tooltip
										width="80"
								>
									<template #default="scope">{{scope.row.depositAmount === 0 ? '' : scope.row.depositAmount}}</template>
								</el-table-column>
								<el-table-column
										label="发货数量"
										align="center" show-overflow-tooltip
										prop="qty"
										width="80"
								/>
								<el-table-column
										label="退货数量"
										align="center" show-overflow-tooltip
										width="80"
								>
									<template #default="scope">{{scope.row.returnQty === 0 ? '' : scope.row.returnQty}}</template>
								</el-table-column>
								<el-table-column
										label="收款日期"
										align="center" show-overflow-tooltip
										prop="receiveDate"
										width="140"
								></el-table-column>
								<el-table-column
										label="退款日期"
										align="center" show-overflow-tooltip
										prop="refundDate"
										width="140"
								></el-table-column>

								<el-table-column
										label="自系统调账日期"
										align="center" show-overflow-tooltip
										prop="systemReconciliationDate"
										width="140"
								></el-table-column>
								<el-table-column
										label="自系统调账数量"
										align="center" show-overflow-tooltip
										prop="systemReconciliationQty"
										width="80"
								></el-table-column>
								<el-table-column
										label="自系统调账金额"
										align="center" show-overflow-tooltip
										prop="systemReconciliationAmount"
										width="80"
								></el-table-column>
								<el-table-column
										label="财务调账日期"
										align="center" show-overflow-tooltip
										prop="reconciliationDate"
										width="140"
								></el-table-column>
								<el-table-column
										label="财务调账数量"
										align="center" show-overflow-tooltip
										prop="reconciliationQty"
										width="80"
								></el-table-column>
								<el-table-column
										label="财务调账金额"
										align="center" show-overflow-tooltip
										prop="reconciliationAmount"
										width="80"
								></el-table-column>
								<el-table-column
										label="单据编号"
										align="center" show-overflow-tooltip
										prop="orderNo"
										width="80"
								></el-table-column>
                <el-table-column
                        label="对账系统平台名称"
                        width="80"
                        align="center" show-overflow-tooltip
                        prop="secordSourceName"
                />
                <el-table-column
                        label="内部系统电商平台名称"
                        align="center" show-overflow-tooltip
                        prop="innerShopName"
                        width="80"
                ></el-table-column>
                <el-table-column
                        label="自有平台主订单号"
                        align="center" show-overflow-tooltip
                        prop="onwerPreformNo"
                        width="80"
                ></el-table-column>
                <el-table-column
                        label="PO单号"
                        align="center" show-overflow-tooltip
                        prop="poNo"
                        width="80"
                ></el-table-column>
                <el-table-column
                        label="入账主体"
                        align="center" show-overflow-tooltip
                        prop="receiveCompany"
                        width="80"
                ></el-table-column>
                <el-table-column
                        label="商品单价"
                        align="center" show-overflow-tooltip
                        prop="price"
                        width="80"
                ></el-table-column>
                <el-table-column
                        label="差异数量"
                        align="center" show-overflow-tooltip
                        prop="differenceQty"
                        width="80"
                ></el-table-column>
                <el-table-column
                        label="是否核销"
                        align="center" show-overflow-tooltip
                        prop="audit"
                        width="80"
                ></el-table-column>
                <el-table-column
                        label="异常售后未提报金额"
                        align="center" show-overflow-tooltip
                        prop="serviceBillAmount"
                        width="80"
                >
                  <template #default="scope">
                    {{scope.row.serviceBillAmount === 0 ? '' : scope.row.serviceBillAmount}}
                  </template>
                </el-table-column>
                <el-table-column
                        label="编号编码"
                        align="center" show-overflow-tooltip
                        prop="ruleCode"
                        width="80"
                ></el-table-column>
								<el-table-column
										label="规则名称"
										align="center" show-overflow-tooltip
										prop="ruleName"
										width="80"
								/>
              </el-table>

              <pagination
                      v-if="total > 0"
                      v-model:total="total"
                      v-model:page="queryParams.pageNum"
                      v-model:limit="queryParams.pageSize"
                      @pagination="handleAuditQuery"
              />
            </el-tab-pane>
            <el-tab-pane label="个人已办未归档" name="done">
              <el-table
                      :height="tableHeight"
                      size="small"
                      :header-row-style="{color: 'dimgray'}"
                      v-loading="loading"
                      :data="doneAuditList"
                      border
                      fixed="left"
              >
								<el-table-column type="selection" width="50" align="center" />
								<el-table-column
										fixed="left"
										label="原始单据ID"
										align="center" show-overflow-tooltip
										width="180"
								>
									<template #default="scope">
										<img v-if="scope.row.manager === 1" src="@/assets/hot.gif"/><a style="color:cornflowerblue"
																									 href="javascript:;"
																									 @click="goDetail(scope.row.id, scope.row.linkNo, 1)">{{scope.row.linkNo}}</a>
									</template>
								</el-table-column>
								<el-table-column
										label="内部系统店铺名称"
										align="center" show-overflow-tooltip
										prop="shopName"
										width="80"
								/>
								<el-table-column
										label="财务系统店铺名称"
										align="center" show-overflow-tooltip
										prop="billSysStoreName"
										width="80"
								></el-table-column>
								<el-table-column
										label="电商平台店铺名称"
										align="center" show-overflow-tooltip
										prop="thirdSourceName"
										width="80"
								></el-table-column>
								<el-table-column
										label="业务日期"
										align="center" show-overflow-tooltip
										prop="businessDate"
										width="140"
								/>
								<el-table-column
										label="核销结果分类"
										align="center" show-overflow-tooltip
										prop="mainTypeName"
										width="80"
								></el-table-column>
								<el-table-column
										label="订单核销细类名称"
										align="center" show-overflow-tooltip
										prop="auditDetailName"
										width="80"
								/>
								<el-table-column
										label="核销状态"
										align="center" show-overflow-tooltip
										prop="auditStatus"
										width="80"
								/>
								<el-table-column
										label="应收账款余额"
										align="center" show-overflow-tooltip
										prop="receiveBillAmount"
										width="80"
								/>
								<el-table-column
										label="发货金额"
										align="center" show-overflow-tooltip
										prop="sendAmount"
										width="80"
								/>
								<el-table-column
										label="退货金额"
										align="center" show-overflow-tooltip
										width="80"
								>
									<template #default="scope">{{scope.row.returnAmount === 0 ? '' : scope.row.returnAmount}}</template>
								</el-table-column>
								<el-table-column
										label="收款金额"
										align="center" show-overflow-tooltip
										prop="receiveAmount"
										width="80"
								/>
								<el-table-column
										label="退款金额"
										align="center" show-overflow-tooltip
										width="80"
								>
									<template #default="scope">{{scope.row.refundAmount === 0 ? '' : scope.row.refundAmount}}</template>
								</el-table-column>
								<el-table-column
										label="保证金退款金额"
										align="center" show-overflow-tooltip
										width="80"
								>
									<template #default="scope">{{scope.row.depositAmount === 0 ? '' : scope.row.depositAmount}}</template>
								</el-table-column>
								<el-table-column
										label="发货数量"
										align="center" show-overflow-tooltip
										prop="qty"
										width="80"
								/>
								<el-table-column
										label="退货数量"
										align="center" show-overflow-tooltip
										width="80"
								>
									<template #default="scope">{{scope.row.returnQty === 0 ? '' : scope.row.returnQty}}</template>
								</el-table-column>
								<el-table-column
										label="收款日期"
										align="center" show-overflow-tooltip
										prop="receiveDate"
										width="140"
								></el-table-column>
								<el-table-column
										label="退款日期"
										align="center" show-overflow-tooltip
										prop="refundDate"
										width="140"
								></el-table-column>
								<el-table-column
										label="自系统调账日期"
										align="center" show-overflow-tooltip
										prop="systemReconciliationDate"
										width="140"
								></el-table-column>
								<el-table-column
										label="自系统调账数量"
										align="center" show-overflow-tooltip
										prop="systemReconciliationQty"
										width="80"
								></el-table-column>
								<el-table-column
										label="自系统调账金额"
										align="center" show-overflow-tooltip
										prop="systemReconciliationAmount"
										width="80"
								></el-table-column>
								<el-table-column
										label="财务调账日期"
										align="center" show-overflow-tooltip
										prop="reconciliationDate"
										width="140"
								></el-table-column>
								<el-table-column
										label="财务调账数量"
										align="center" show-overflow-tooltip
										prop="reconciliationQty"
										width="80"
								></el-table-column>
								<el-table-column
										label="财务调账金额"
										align="center" show-overflow-tooltip
										prop="reconciliationAmount"
										width="80"
								></el-table-column>
								<el-table-column
										label="单据编号"
										align="center" show-overflow-tooltip
										prop="orderNo"
										width="80"
								></el-table-column>
								<el-table-column
										label="对账系统平台名称"
										width="80"
										align="center" show-overflow-tooltip
										prop="secordSourceName"
								/>
								<el-table-column
										label="内部系统电商平台名称"
										align="center" show-overflow-tooltip
										prop="innerShopName"
										width="80"
								></el-table-column>
								<el-table-column
										label="自有平台主订单号"
										align="center" show-overflow-tooltip
										prop="onwerPreformNo"
										width="80"
								></el-table-column>
								<el-table-column
										label="PO单号"
										align="center" show-overflow-tooltip
										prop="poNo"
										width="80"
								></el-table-column>
								<el-table-column
										label="入账主体"
										align="center" show-overflow-tooltip
										prop="receiveCompany"
										width="80"
								></el-table-column>
								<el-table-column
										label="商品单价"
										align="center" show-overflow-tooltip
										prop="price"
										width="80"
								></el-table-column>
								<el-table-column
										label="差异数量"
										align="center" show-overflow-tooltip
										prop="differenceQty"
										width="80"
								></el-table-column>
								<el-table-column
										label="是否核销"
										align="center" show-overflow-tooltip
										prop="audit"
										width="80"
								></el-table-column>
								<el-table-column
										label="异常售后未提报金额"
										align="center" show-overflow-tooltip
										prop="serviceBillAmount"
										width="80"
								>
									<template #default="scope">
										{{scope.row.serviceBillAmount === 0 ? '' : scope.row.serviceBillAmount}}
									</template>
								</el-table-column>
								<el-table-column
										label="编号编码"
										align="center" show-overflow-tooltip
										prop="ruleCode"
										width="80"
								></el-table-column>
								<el-table-column
										label="规则名称"
										align="center" show-overflow-tooltip
										prop="ruleName"
										width="80"
								/>
              </el-table>

              <pagination
                      v-if="doneTotal > 0"
                      v-model:total="doneTotal"
                      v-model:page="queryParams.pageNum"
                      v-model:limit="queryParams.pageSize"
                      @pagination="getDoneAuditPage"
              />
            </el-tab-pane>
            <el-tab-pane label="个人归档" name="file">
              <el-table
                      :height="tableHeight"
                      size="small"
                      :header-row-style="{color: 'dimgray'}"
                      v-loading="loading"
                      :data="doneAuditList"
                      fixed="left"
                      border>
								<el-table-column type="selection" width="50" align="center" />
								<el-table-column
										fixed="left"
										label="原始单据ID"
										align="center" show-overflow-tooltip
										width="180"
								>
									<template #default="scope">
										<img v-if="scope.row.manager === 1" src="@/assets/hot.gif"/><a style="color:cornflowerblue"
																									 href="javascript:;"
																									 @click="goDetail(scope.row.id, scope.row.linkNo, 1)">{{scope.row.linkNo}}</a>
									</template>
								</el-table-column>
								<el-table-column
										label="内部系统店铺名称"
										align="center" show-overflow-tooltip
										prop="shopName"
										width="80"
								/>
								<el-table-column
										label="财务系统店铺名称"
										align="center" show-overflow-tooltip
										prop="billSysStoreName"
										width="80"
								></el-table-column>
								<el-table-column
										label="电商平台店铺名称"
										align="center" show-overflow-tooltip
										prop="thirdSourceName"
										width="80"
								></el-table-column>
								<el-table-column
										label="业务日期"
										align="center" show-overflow-tooltip
										prop="businessDate"
										width="140"
								/>
								<el-table-column
										label="核销结果分类"
										align="center" show-overflow-tooltip
										prop="mainTypeName"
										width="80"
								></el-table-column>
								<el-table-column
										label="订单核销细类名称"
										align="center" show-overflow-tooltip
										prop="auditDetailName"
										width="80"
								/>
								<el-table-column
										label="核销状态"
										align="center" show-overflow-tooltip
										prop="auditStatus"
										width="80"
								/>
								<el-table-column
										label="应收账款余额"
										align="center" show-overflow-tooltip
										prop="receiveBillAmount"
										width="80"
								/>
								<el-table-column
										label="发货金额"
										align="center" show-overflow-tooltip
										prop="sendAmount"
										width="80"
								/>
								<el-table-column
										label="退货金额"
										align="center" show-overflow-tooltip
										width="80"
								>
									<template #default="scope">{{scope.row.returnAmount === 0 ? '' : scope.row.returnAmount}}</template>
								</el-table-column>
								<el-table-column
										label="收款金额"
										align="center" show-overflow-tooltip
										prop="receiveAmount"
										width="80"
								/>
								<el-table-column
										label="退款金额"
										align="center" show-overflow-tooltip
										width="80"
								>
									<template #default="scope">{{scope.row.refundAmount === 0 ? '' : scope.row.refundAmount}}</template>
								</el-table-column>
								<el-table-column
										label="保证金退款金额"
										align="center" show-overflow-tooltip
										width="80"
								>
									<template #default="scope">{{scope.row.depositAmount === 0 ? '' : scope.row.depositAmount}}</template>
								</el-table-column>
								<el-table-column
										label="发货数量"
										align="center" show-overflow-tooltip
										prop="qty"
										width="80"
								/>
								<el-table-column
										label="退货数量"
										align="center" show-overflow-tooltip
										width="80"
								>
									<template #default="scope">{{scope.row.returnQty === 0 ? '' : scope.row.returnQty}}</template>
								</el-table-column>
								<el-table-column
										label="收款日期"
										align="center" show-overflow-tooltip
										prop="receiveDate"
										width="140"
								></el-table-column>
								<el-table-column
										label="退款日期"
										align="center" show-overflow-tooltip
										prop="refundDate"
										width="140"
								/>
								<el-table-column
										label="自系统调账日期"
										align="center" show-overflow-tooltip
										prop="systemReconciliationDate"
										width="140"
								></el-table-column>
								<el-table-column
										label="自系统调账数量"
										align="center" show-overflow-tooltip
										prop="systemReconciliationQty"
										width="80"
								></el-table-column>
								<el-table-column
										label="自系统调账金额"
										align="center" show-overflow-tooltip
										prop="systemReconciliationAmount"
										width="80"
								></el-table-column>
								<el-table-column
										label="财务调账日期"
										align="center" show-overflow-tooltip
										prop="reconciliationDate"
										width="140"
								></el-table-column>
								<el-table-column
										label="财务调账数量"
										align="center" show-overflow-tooltip
										prop="reconciliationQty"
										width="80"
								></el-table-column>
								<el-table-column
										label="财务调账金额"
										align="center" show-overflow-tooltip
										prop="reconciliationAmount"
										width="80"
								></el-table-column>
								<el-table-column
										label="单据编号"
										align="center" show-overflow-tooltip
										prop="orderNo"
										width="80"
								></el-table-column>
								<el-table-column
										label="对账系统平台名称"
										width="80"
										align="center" show-overflow-tooltip
										prop="secordSourceName"
								/>
								<el-table-column
										label="内部系统电商平台名称"
										align="center" show-overflow-tooltip
										prop="innerShopName"
										width="80"
								></el-table-column>
								<el-table-column
										label="自有平台主订单号"
										align="center" show-overflow-tooltip
										prop="onwerPreformNo"
										width="80"
								></el-table-column>
								<el-table-column
										label="PO单号"
										align="center" show-overflow-tooltip
										prop="poNo"
										width="80"
								></el-table-column>
								<el-table-column
										label="入账主体"
										align="center" show-overflow-tooltip
										prop="receiveCompany"
										width="80"
								></el-table-column>
								<el-table-column
										label="商品单价"
										align="center" show-overflow-tooltip
										prop="price"
										width="80"
								></el-table-column>
								<el-table-column
										label="差异数量"
										align="center" show-overflow-tooltip
										prop="differenceQty"
										width="80"
								></el-table-column>
								<el-table-column
										label="是否核销"
										align="center" show-overflow-tooltip
										prop="audit"
										width="80"
								></el-table-column>
								<el-table-column
										label="异常售后未提报金额"
										align="center" show-overflow-tooltip
										prop="serviceBillAmount"
										width="80"
								>
									<template #default="scope">
										{{scope.row.serviceBillAmount === 0 ? '' : scope.row.serviceBillAmount}}
									</template>
								</el-table-column>
								<el-table-column
										label="编号编码"
										align="center" show-overflow-tooltip
										prop="ruleCode"
										width="80"
								/>
								<el-table-column
										label="规则名称"
										align="center" show-overflow-tooltip
										prop="ruleName"
										width="80"
								></el-table-column>
              </el-table>

              <pagination
                      v-if="doneTotal > 0"
                      v-model:total="doneTotal"
                      v-model:page="queryParams.pageNum"
                      v-model:limit="queryParams.pageSize"
                      @pagination="getDoneAuditPage"
              />
            </el-tab-pane>
          </el-tabs>

        </el-card>
      </el-col>
    </el-row>

    <!-- 导入弹窗 -->
    <el-dialog
            v-model="importDialog.visible"
            :title="importDialog.title"
            width="600px"
            append-to-body
            :close-on-click-modal="false"
            @close="closeImportDialog"
    >
      <el-form label-width="80px">
        <el-form-item label="Excel">
          <el-upload
                  class="upload-demo"
                  action=""
                  drag
                  :auto-upload="false"
                  accept="application/vnd.openxmlformats-officedocument.spreadsheetml.sheet, application/vnd.ms-excel"
                  :file-list="excelFilelist"
                  :on-change="handleExcelChange"
                  :limit="1"
          >
            <el-icon class="el-icon--upload">
              <i-ep-upload-filled />
            </el-icon>
            <div class="el-upload__text">
              将文件拖到此处，或
              <em>点击上传</em>
            </div>
            <template #tip>
              <div class="el-upload__tip">xls/xlsx files</div>
            </template>
          </el-upload>
        </el-form-item>
      </el-form>
      <template #footer>
        <div class="dialog-footer">
          <el-button type="primary" @click="handleAuditImport">确 定</el-button>
          <el-button @click="closeImportDialog">取 消</el-button>
        </div>
      </template>
    </el-dialog>
    <el-dialog
            v-model="resultDialog.visible"
            :title="resultDialog.title"
            width="600px"
            append-to-body
            :close-on-click-modal="false"
            @close="closeImportResultDialog"
    >
      <span v-for="msg in importMsg">{{msg}}<br></span>
    </el-dialog>
  </div>
</template>
